<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="定义流程列表" libs=["table"]/>
<div class="container-div" id="_app">
	<div class="row">
        <div class="col-sm-12 search-collapse">
            <@f.form id="module-form">
                <div class="select-list">
                    <ul>
                        <li>
                            <@ctx.i18n text = "流程标题"/>：
                            <input type="text" class="form-control" name="title"/>
                        </li>
                        <li>
                            <@ctx.i18n text = "状态"/>：
                            <@f.select name="status" dictType="bpm_form_draft_status" blankValue="" blankLabel="所有"/>
                        </li>
                        <li>
                            <@ctx.i18n text = "表单类型"/>：
                            <@f.select name="tableType" dictType="sys_table_type" blankValue="" blankLabel="所有"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>  <@ctx.i18n text = "查询"/></a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i> <@ctx.i18n text = "重置"/></a>
                        </li>
                    </ul>
                </div>
            </@f.form>
           </div>
    <@table id="bootstrap-table"/>
    </div>
</div>
<@footer>
<script type="text/javascript">
    var prefix = baseURL + "bpm/formdraft";
    var editFlag = "${permission.hasPermi('sys:comp:edit')}";
    var statusDatas = ${dict.getDictListJson('bpm_form_draft_status')};
    var tableTypes = ${dict.getDictListJson('sys_table_type')};
    $(function() {
        var options = {
            url: prefix + "/list",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            clickToSelect: true,
            delUrl: prefix + "/del",
            uniqueId:    'id'                           , /* 唯一ID */
            columns: [
                {title: $.i18n.prop("序号"), width: 5, align: "center", formatter: function (value, row, index) {
                    return $.table.serialNumber(index);}},
                {field : 'title',title : '<@ctx.i18n text = "标题"/>'},
                {field : 'status',title : '<@ctx.i18n text = "状态"/>',formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);}},
                {field : 'createTime',title : '<@ctx.i18n text = "创建时间"/>'},
                {field : 'tableType',title : '表单分类',formatter: function(value, item, index) {
                        return $.table.selectDictLabel(tableTypes,value);}},
                {title:"<@ctx.i18n text = "操作"/>",align: 'left',width:240,class:'action',formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status==1){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="sendForm(\'' + row.url + '\',\''+row.id+'\')"><i style="color:white;" class="fa fa-play"></i> <@ctx.i18n text = "发布"/></a> ');
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="editForm(\'' + row.url + '\',\''+row.formDataId+'\')"><i style="color:white;" class="fa fa-edit"></i> <@ctx.i18n text = "编辑"/></a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="deleteForm(\'' + row.url + '\',\''+row.id+'\')"><i style="color:white;" class="fa fa-trash"></i> <@ctx.i18n text = "删除"/></a> ');
                        }
                        if(row.status==2){
                            actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="preview(\'' + row.url + '\',\''+row.formDataId+'\')"><i style="color:white;" class="fa fa-eye"></i> <@ctx.i18n text = "预览"/></a> ');
                        }
                        return actions.join('');
                }}
            ]
        };
        $.table.init(options);
    });

    //发送表单
    function sendForm(url, id) {
        //直接调用对应表单的send方法，进行流程发起
        opt.operate.post(baseURL + url + "/send", { "formDraftId": id});
    }

    function deleteForm(url,id) {
        console.log(url)
        console.log("我真的是id"+id)
        opt.modal.confirm("确认要删除待发流程吗?", function() {
            opt.operate.post(prefix + "/del", { "formDraftId": id});
        })
    }

    /*修改*/
    function editForm(url, id) {
        window.open(baseURL + url + "/edit?taskId=&businessKey="+id);
    }

    /*预览*/
    function preview(url, id) {
        window.open(baseURL + url + "/view?taskId=&businessKey="+id);
    }

</script>
</@footer>
</@pageTheme>